import testRule from './__helpers__/helper'
import * as fs from 'fs'
import { parse } from 'yaml'

const snaptradeOas = parse(
  fs.readFileSync(`${__dirname}/snaptrade-missing-descriptions.yaml`, 'utf-8')
)

testRule('array-items-schema-missing-description', [
  {
    name: 'snaptrade-array-items-schema-missing-descriptions',
    document: snaptradeOas,
    errors: [
      {
        path: [
          'paths',
          '/snapTrade/listUsers',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/snapTrade/partners',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'allowed_brokerages',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/snapTrade/partners',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'allowed_brokerages',
          'items',
          'properties',
          'exchanges',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/holdings',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
          'properties',
          'account',
          'properties',
          'brokerage_authorization',
          'properties',
          'brokerage',
          'properties',
          'exchanges',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/holdings',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'option_postions',
          'items',
          'properties',
          'symbol',
          'properties',
          'brokerage_authorization',
          'properties',
          'brokerage',
          'properties',
          'exchanges',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/quotes',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/options',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
          'properties',
          'symbol',
          'properties',
          'brokerage_authorization',
          'properties',
          'brokerage',
          'properties',
          'exchanges',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/optionsChain',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/optionsChain',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
          'properties',
          'chainPerRoot',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/optionsChain',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
          'properties',
          'chainPerRoot',
          'items',
          'properties',
          'chainPerStrikePrice',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/optionStrategy',
          'post',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'strategy',
          'properties',
          'legs',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/optionStrategy/{optionStrategyId}',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'strategy',
          'properties',
          'legs',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/accounts/{accountId}/optionStrategy/{optionStrategyId}/execute',
          'post',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'strategy',
          'properties',
          'legs',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/authorizations',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/authorizations',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
          'properties',
          'brokerage',
          'properties',
          'exchanges',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/authorizations/{authorizationId}',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'brokerage',
          'properties',
          'exchanges',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/sessionEvents',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/brokerages',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/brokerages',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
          'properties',
          'exchanges',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/brokerageAuthorizationTypes',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'badTickers',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'contributionTimeframe',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'contributionTimeframeCumulative',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'dividendTimeline',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'dividendTimeline',
          'items',
          'properties',
          'dividends',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'returnRateTimeframe',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'totalEquityTimeframe',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
      {
        path: [
          'paths',
          '/performance/custom',
          'get',
          'responses',
          '200',
          'content',
          'application/json',
          'schema',
          'properties',
          'withdrawalTimeframe',
          'items',
        ],
        code: 'array-items-schema-missing-description',
      },
    ],
  },
])
